trigger AutoIdentifyOrderItemRecordtype on Order_Item__c (before insert) {
    list<recordtype> rlist=new list<recordtype>();
    id returnorder;
    id freegoods;
    id normal;
    
    rlist=[select id,DeveloperName from recordtype where sobjecttype=:'Order_Item__c' and ( DeveloperName=:'free_goods' or DeveloperName=:'normal' or DeveloperName=:'Return')];
    
    for(recordtype rt:rlist){                            //匹配recordtypeid
        if(rt.DeveloperName=='free_goods'){
            freegoods=rt.id;
        }else if(rt.DeveloperName=='normal'){
            normal=rt.id;
        }else if(rt.DeveloperName=='Return'){
            returnorder=rt.id;
        }
    }
    
    for(Order_Item__c t:trigger.new){                    //recordtype赋值
        if(t.Order_Type__c=='常规'){
            t.recordtypeid=normal;
        }else if(t.Order_Type__c=='退货'){
            t.recordtypeid=returnorder;
        }else if(t.Order_Type__c=='免费产品'){
            t.recordtypeid=freegoods;
        }
    }
    
    
}